package io.github.harmonly.mapper;

import io.github.harmonly.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user where uid = #{uid}")
    User getUser(int uid);

    @Select("select * from user where account = #{account}")
    User getUserByAccount(String account);

    @Select("select * from user where role != 'admin'")
    List<User> getUsers();

    @Select("select * from user where name like '%' #{keyword} '%'")
    List<User> getUsersByKeyWord(String keyword);

    @Insert("insert into user(name, account, password, role, face, phone, qq, birth) VALUES(#{name}, #{account}, #{password}, #{role}, #{face}, #{phone}, #{qq}, #{birth})")
    int addUser(User user);

    @Delete("delete user from user where uid = #{uid}")
    int deleteUser(int uid);

    @Update("update user set name = #{name}, account = #{account}, password = #{password}, role = #{role}, face = #{face}, phone = #{phone}, qq = #{qq}, birth = #{birth} where uid = #{uid}")
    int editUser(User user);
}
